﻿LApp.controller('CommonCtrl', function ($scope, $rootScope, $location, $templateRequest, $http, $state, $lvl, leafletData, leafletHelpers, DBCenterService) {
    // $templateRequest(CONTENT_URL('Pages/Account/ChangePassword.html'));
    // $templateRequest(CONTENT_URL('Pages/DBCenter/Customer/CustomerDetail.html'));
    // $templateRequest(CONTENT_URL('Pages/DBCenter/Customer/CustomerDetailHistory.html'));
    // $templateRequest(CONTENT_URL('Pages/DBCenter/Car/CarDetail.html'));
    function _SetStyle() {
        $scope.LeftStyle = {
            height: (document.documentElement.clientHeight - 50) + "px"
        }

        $scope.RightStyle = {
            height: (document.documentElement.clientHeight - 50) + "px",
            width: (document.documentElement.clientWidth - 250) + "px"
        }

        $scope.BodyStyle = {
            width: document.documentElement.clientWidth + "px",
            height: document.documentElement.clientHeight + "px"
        }
    }

    _SetStyle();

    window.onresize = function () {
        $scope.$apply(_SetStyle);
    }

    //  修改密码
    angular.extend($rootScope, {
        //CheckPassword: function () {
            //$lvl.get(GlobalConfig.APIServer + "api/keepsys/checkpassword",
            //    { UserId: $rootScope.CurrentUser.UserId },
            //    function (response) {
            //        if (response == false) {
            //            $rootScope.Dialog_ChangePassword(true);
            //        }
            //    }, { hideloading: true }
            //);
       // },
        Dialog_ChangePassword: function (focus) {
            $lvl.dialog2({
                title: "修改密码",
                scopeParam: {
                    isFocus: focus
                },
                template: CONTENT_URL('Pages/Account/ChangePassword.html')
            });
        },
    })
})

LApp.controller('ChangePasswordCtrl', function ($scope, $rootScope, $http, $lvl, CommonService) {
    angular.extend($scope, {
        OldPassword: "",
        NewPassword: "",
        ConfirmPassword: "",
        Cancel_LogOut: function (_close) {
            if (_close) _close();
            $rootScope.LogOut();
        },
        SavePassword: function (_form, _close) {
            if ($scope.NewPassword != $scope.ConfirmPassword) {
                $lvl.msgError("两次密码不一致");
                return;
            }

            if ($scope.OldPassword == $scope.NewPassword) {
                $lvl.msgError("新密码和旧密码不能相同");
                return;
            }

            CommonService.ChangePassword({
                data: {
                    UserId: $rootScope.CurrentUser.ID,
                    OldPassword: $scope.OldPassword,
                    NewPassword: $scope.NewPassword
                },
                success: function () {
                    if (_close) _close();
                    $rootScope.LogOut();
                }
            })

        }
    })
})

